package org.example.webserver.service.serviceImpl;

import jakarta.annotation.Resource;
import org.example.webserver.dao.CommodityDao;
import org.example.webserver.pojo.Commodity;
import org.example.webserver.service.CommodityService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommodityServiceImpl implements CommodityService {
    @Resource
    CommodityDao commodityDao;
    @Override
    public List<Commodity> showAllCommodity() {
        List<Commodity> commodityList=commodityDao.findAll();
        return commodityList;
    }

    @Override
    public List<Commodity> searchCommodity(String name) {
        List<Commodity> commodityList=commodityDao.findByNameLike(name);
        return commodityList;
    }

    @Override
    public List<Commodity> searchCommodityByMerchant(String merchant) {
        return commodityDao.findByMerchant(merchant);
    }

    @Override
    public Commodity addCommodity(Commodity commodity) {
        commodity.setId(null);
        commodityDao.save(commodity);
        return null;
    }

    @Override
    public Commodity delCommodity(Commodity commodity) {
        commodityDao.deleteById(commodity.getId());
        return null;
    }

    @Override
    public Commodity editCommodity(Commodity commodity) {
        commodityDao.save(commodity);
        return null;
    }
}
